import { createRouter, createWebHistory } from 'vue-router'
import type { RouteRecordRaw } from 'vue-router'
import BasicLayout from '@/layouts/BasicLayout.vue'

// 静态路由
export const constantRoutes: RouteRecordRaw[] = [
  {
    path: '/login',
    component: () => import('@/views/auth/Login.vue'),
    meta: { hidden: true }
  },
  {
    path: '/register',
    component: () => import('@/views/auth/Register.vue'),
    meta: { hidden: true }
  },
  {
    path: '/',
    component: BasicLayout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/Dashboard.vue'),
        name: 'Dashboard',
        meta: { title: '首页', icon: 'dashboard' }
      },
      {
        path: 'profile',
        component: () => import('@/views/profile/Profile.vue'),
        name: 'Profile',
        meta: { title: '个人资料', icon: 'profile' }
      }
    ]
  }
]

// 异步路由（需要权限验证）
export const asyncRoutes: RouteRecordRaw[] = [
  {
    path: '/member',
    component: BasicLayout,
    name: 'Member',
    meta: { title: '会员管理', icon: 'user' },
    children: [
      {
        path: 'list',
        component: () => import('@/views/member/MemberList.vue'),
        name: 'MemberList',
        meta: { title: '会员列表', icon: 'table' }
      }
    ]
  },
  {
    path: '/course',
    component: BasicLayout,
    name: 'Course',
    meta: { title: '课程管理', icon: 'education' },
    children: [
      {
        path: 'list',
        component: () => import('@/views/course/CourseList.vue'),
        name: 'CourseList',
        meta: { title: '课程列表', icon: 'table' }
      },
      {
        path: 'category',
        component: () => import('@/views/course/CategoryList.vue'),
        name: 'CategoryList',
        meta: { title: '分类管理', icon: 'category' }
      }
    ]
  },
  {
    path: '/coach',
    component: BasicLayout,
    name: 'Coach',
    meta: { title: '教练管理', icon: 'avatar' },
    children: [
      {
        path: 'list',
        component: () => import('@/views/coach/CoachList.vue'),
        name: 'CoachList',
        meta: { title: '教练列表', icon: 'table' }
      }
    ]
  },
  {
    path: '/plan',
    component: BasicLayout,
    name: 'Plan',
    meta: { title: '健身计划', icon: 'notebook' },
    children: [
      {
        path: 'list',
        component: () => import('@/views/plan/PlanList.vue'),
        name: 'PlanList',
        meta: { title: '计划列表', icon: 'table' }
      }
    ]
  },
  {
    path: '/booking',
    component: BasicLayout,
    name: 'Booking',
    meta: { title: '课程预约', icon: 'calendar' },
    children: [
      {
        path: 'list',
        component: () => import('@/views/booking/BookingList.vue'),
        name: 'BookingList',
        meta: { title: '预约列表', icon: 'table' }
      }
    ]
  },
  {
    path: '/card',
    component: BasicLayout,
    name: 'Card',
    meta: { title: '会员卡管理', icon: 'credit-card' },
    children: [
      {
        path: 'list',
        component: () => import('@/views/card/CardList.vue'),
        name: 'CardList',
        meta: { title: '会员卡列表', icon: 'table' }
      },
      {
        path: 'type',
        component: () => import('@/views/card/CardTypeList.vue'),
        name: 'CardTypeList',
        meta: { title: '卡类型管理', icon: 'tickets' }
      }
    ]
  },
  {
    path: '/checkin',
    component: BasicLayout,
    name: 'Checkin',
    meta: { title: '签到打卡', icon: 'location' },
    children: [
      {
        path: 'record',
        component: () => import('@/views/checkin/CheckinRecordList.vue'),
        name: 'CheckinRecordList',
        meta: { title: '签到记录', icon: 'document' }
      }
    ]
  },
  {
    path: '/statistics',
    component: BasicLayout,
    name: 'Statistics',
    meta: { title: '数据统计', icon: 'data-analysis' },
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/statistics/Dashboard.vue'),
        name: 'StatisticsDashboard',
        meta: { title: '统计概览', icon: 'odometer' }
      }
    ]
  },
  {
    path: '/notification',
    component: BasicLayout,
    name: 'Notification',
    meta: { title: '通知管理', icon: 'message' },
    children: [
      {
        path: '',
        component: () => import('@/views/notification/index.vue'),
        name: 'NotificationCenter',
        meta: { title: '通知中心', icon: 'message' }
      },
      {
        path: 'list',
        component: () => import('@/views/notification/NotificationList.vue'),
        name: 'NotificationList',
        meta: { title: '通知列表', icon: 'notification' }
      },
      {
        path: 'announcement',
        component: () => import('@/views/notification/AnnouncementList.vue'),
        name: 'AnnouncementList',
        meta: { title: '公告管理', icon: 'bell' }
      },
      {
        path: 'settings',
        component: () => import('@/views/notification/NotificationSettings.vue'),
        name: 'NotificationSettings',
        meta: { title: '通知设置', icon: 'setting' }
      },
      {
        path: 'templates',
        component: () => import('@/views/notification/TemplateList.vue'),
        name: 'TemplateList',
        meta: { title: '模板管理', icon: 'document' }
      }
    ]
  },
  {
    path: '/review',
    component: BasicLayout,
    name: 'Review',
    meta: { title: '评价反馈', icon: 'comment' },
    children: [
      {
        path: '',
        component: () => import('@/views/review/index.vue'),
        name: 'ReviewCenter',
        meta: { title: '评价中心', icon: 'comment' }
      },
      {
        path: 'course',
        component: () => import('@/views/review/CourseReviewList.vue'),
        name: 'CourseReviewList',
        meta: { title: '课程评价', icon: 'star' }
      },
      {
        path: 'coach',
        component: () => import('@/views/review/CoachRatingList.vue'),
        name: 'CoachRatingList',
        meta: { title: '教练评分', icon: 'user' }
      },
      {
        path: 'feedback',
        component: () => import('@/views/review/FeedbackList.vue'),
        name: 'FeedbackList',
        meta: { title: '意见反馈', icon: 'feedback' }
      },
      {
        path: 'statistics',
        component: () => import('@/views/review/ReviewStatistics.vue'),
        name: 'ReviewStatistics',
        meta: { title: '评价统计', icon: 'data-analysis' }
      },
      {
        path: 'reports',
        component: () => import('@/views/review/ReviewReportList.vue'),
        name: 'ReviewReportList',
        meta: { title: '举报管理', icon: 'warning' }
      }
    ]
  },
  {
    path: '/system',
    component: BasicLayout,
    name: 'System',
    meta: { title: '系统管理', icon: 'setting' },
    children: [
      {
        path: 'user',
        component: () => import('@/views/system/UserList.vue'),
        name: 'UserList',
        meta: { title: '用户管理', icon: 'user' }
      },
      {
        path: 'role',
        component: () => import('@/views/system/RoleList.vue'),
        name: 'RoleList',
        meta: { title: '角色管理', icon: 'avatar' }
      },
      {
        path: 'permission',
        component: () => import('@/views/system/PermissionManagement.vue'),
        name: 'PermissionManagement',
        meta: { title: '权限管理', icon: 'lock' }
      },
      {
        path: 'config',
        component: () => import('@/views/system/SystemConfig.vue'),
        name: 'SystemConfig',
        meta: { title: '系统配置', icon: 'document' }
      },
      {
        path: 'logs',
        component: () => import('@/views/system/OperationLog.vue'),
        name: 'OperationLog',
        meta: { title: '操作日志', icon: 'document' }
      },
      {
        path: 'menu',
        component: () => import('@/views/system/MenuList.vue'),
        name: 'MenuList',
        meta: { title: '菜单管理', icon: 'menu' }
      }
    ]
  },
  {
    path: '/file',
    component: BasicLayout,
    name: 'File',
    meta: { title: '文件管理', icon: 'folder' },
    children: [
      {
        path: '',
        component: () => import('@/views/file/index.vue'),
        name: 'FileCenter',
        meta: { title: '文件中心', icon: 'folder' }
      },
      {
        path: 'list',
        component: () => import('@/views/file/FileList.vue'),
        name: 'FileList',
        meta: { title: '文件列表', icon: 'document' }
      },
      {
        path: 'training-photos',
        component: () => import('@/views/file/TrainingPhotoList.vue'),
        name: 'TrainingPhotoList',
        meta: { title: '训练照片', icon: 'camera' }
      },
      {
        path: 'certificates',
        component: () => import('@/views/file/CoachCertificateList.vue'),
        name: 'CoachCertificateList',
        meta: { title: '教练证书', icon: 'medal' }
      }
    ]
  },
  {
    path: '/chat',
    component: BasicLayout,
    name: 'Chat',
    meta: { title: '在线客服', icon: 'chat-dot-round' },
    children: [
      {
        path: 'workspace',
        component: () => import('@/views/chat/ChatWorkspace.vue'),
        name: 'ChatWorkspace',
        meta: { title: '客服工作台', icon: 'service' }
      },
      {
        path: 'sessions',
        component: () => import('@/views/chat/SessionList.vue'),
        name: 'SessionList',
        meta: { title: '会话管理', icon: 'chat-line-round' }
      },
      {
        path: 'quick-replies',
        component: () => import('@/views/chat/QuickReplyList.vue'),
        name: 'QuickReplyList',
        meta: { title: '快捷回复', icon: 'chat-dot-square' }
      }
    ]
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes: [...constantRoutes, ...asyncRoutes]
})

export default router
